import * as Apis from "../../apis/Api";
import { observable, action } from 'mobx';
import { Button } from 'antd';
import {WeaTableNew} from 'comsMobx';
const {TableStore} = WeaTableNew;

class ContractTypeStore {


    @observable routerParams = {page:'getReportByType'};
    @observable years = [];//年份
    @observable contract_amount_targets = [];
    @observable contract_amounts = [];
    @observable contract_quantity_targets = [];
    @observable contract_quantitys = [];
    @observable names = [];
    @observable loading = false;
    @observable tabKey = 1;
    @observable tableStore = new TableStore();
    @observable showList = false;
    @observable requestParams = {};

    init = (routerParams) => {
        this.routerParams = routerParams;
    }

    @action
    reLoad = ()=>{
        this.doSearch(this.requestParams);
    }

    @action
    doSearch = (requestParams) => {

        let params = { ...this.routerParams, ...requestParams };
        const yeartype = requestParams.yeartype;
        const myDate = new Date();
        //年份处理
        if (yeartype == "1") {
            params.year = myDate.getFullYear();
        } else if (yeartype == "2") {
            params.year = myDate.getFullYear() - 1;
        } else {

        }

        if ("undefined" != typeof (params.year) && "" != params.year) {
            this.loading = true;
            Apis.getReportInfo(params).then(data => {
                this.requestParams = params;
                this.tableStore.getDatas(data.datas.sessionkey, 1,10,"",this.mathChart);
            });
        }
    }


    @action
    mathChart = ()=>{
        let names = [];
        let contract_amount_targets = [];
        let contract_amounts = [];
        let contract_quantity_targets = [];
        let contract_quantitys = [];

        const storeDatas = this.tableStore.datas;
        storeDatas.map(c=>{
            contract_amount_targets.push(c.contract_amount_target||0);
            contract_amounts.push(c.contract_amount||0);
            contract_quantity_targets.push(c.contract_quantity_target||0);
            contract_quantitys.push(c.contract_quantity||0);
            names.push(c.name);
        });

        this.contract_amount_targets = contract_amount_targets;
        this.contract_amounts = contract_amounts;
        this.contract_quantity_targets = contract_quantity_targets;
        this.contract_quantitys = contract_quantitys;
        this.names = names;

        this.loading = false;
        this.years = [`${this.requestParams.year}`, `${Number(this.requestParams.year) - 1}`];
        
    }

    @action
    changeTab = (tabKey) => {
        this.tabKey = tabKey;
    }

    @action
    changeShowList = (bl) => {
        this.showList = (!bl);
    }
}

export default ContractTypeStore;